Let’s learn how to use a function. For this, we need to add arguments to the function call.
?head?names?plot
In the R script…
Let’s have a look at a data set: mtcars. What is it about?
To execute a line of code, use Shift + Enter.
Excursion: Classes
numeric (1.34, -10.6)
integer (1, -99)
character ("hello", "world")
NAs: “not assigned”
factors
Pop quiz
What class does this result have?
Pop quiz – NAs
What’s the result?
Let’s plot this data set, specifically the columns mpg and hp. To access them, we have to put a $ between the name of the data set and the name of the column. It will show up in the Plots pane.
Comments
We’re still in the R script. What if we want to explain to others (or our future self) what we intended with this code?
Assigning (<-)
What if we want to create a new object? Easy:
Packages
What if we want more functions? We install packages, which contain functions. We install them once (in the console).
We can then load them (once per script).
Your turn!
Have a look at the dataset palmerpenguins. What is it about? Plot a scatterplot.
Comments
We’re still in the R script. What if we want to explain to others (or our future self) what we intended with this code?